package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.response.RepairManageItemBean;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-18  16:03
 * @Description:添加维保管理页面的适配器，是维修车辆 还是 保养车辆；
 */
public class RepairManageListAdapter extends BaseQuickAdapter<RepairManageItemBean, BaseViewHolder> {
    public RepairManageListAdapter(int layoutResId, @Nullable List<RepairManageItemBean> data) {
        super(layoutResId, data);

        //设置点击事件；
        addChildClickViewIds(//
                R.id.textviewrepairintostation,//
                R.id.linearlayoutcallphonewrap,//拨打电话
                R.id.textviewbookingchange,//
                R.id.textviewbookingcancel,//
                R.id.textviewbookingsure);//

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, RepairManageItemBean repairManageItemBean) {


        if (repairManageItemBean != null) {

            //设置item数据；
            //获取这个标题大名字 是车牌号
            String carNumber = repairManageItemBean.getCarNo();

            //获取联系人姓名
            String personName = repairManageItemBean.getCustomerName();

            //顾问姓名,是要搜索顾问名称的
            String managerName = repairManageItemBean.getManagerName();

            //获取这个条目的状态 :文字形式
            String personPhone = repairManageItemBean.getPhone();


            //2、显示预约时间：优先展示changeAppointmentTime，如果changeAppointmentTime为空，展示预约日期+预约时段（appointmentTime+expectedPeriod）
            //2、显示预约时间：优先展示changeAppointmentTime，如果changeAppointmentTime为空，展示预约日期+预约时段（appointmentTime+expectedPeriod）
            String timeResult = "";
            //选中的预约时间
            String changeAppointmentTime = repairManageItemBean.getChangeAppointmentTime();
            //预约日期
            String appointmentTime = repairManageItemBean.getAppointmentTime();
            //预约时间段
            String expectedPeriod = repairManageItemBean.getExpectedPeriod();

            if (!TextUtils.isEmpty(changeAppointmentTime)) {
                timeResult = changeAppointmentTime;
            } else {
                timeResult = appointmentTime + StringUtils.getString(R.string.kongge0) + expectedPeriod;
            }

            //客户的意图标签，是要【预约维修】 还是要【预约保养】
            String typeRepair = repairManageItemBean.getAppointmentTypeInfo();

            //该条目的分配状态
            String itemState = repairManageItemBean.getHandleStatusInfo();


            //findViews
            //勾选按钮：
//            CheckBox checkBoxInRepairManage = (CheckBox) baseViewHolder.getView(R.id.checkboxinrepairmanage);

            //车牌号信息
            TextView textViewCarnumberName = (TextView) baseViewHolder.getView(R.id.textviewcarnumbername);
            //车辆的 维修还是保养的区分标签
            RoundTextView textViewRepairTypeTag = (RoundTextView) baseViewHolder.getView(R.id.textviewrepairtypetag);
            //改单子的分配状态
            TextView textViewRepairAssignedState = (TextView) baseViewHolder.getView(R.id.textviewrepairassignedstate);

            //汽车销售顾问的名称
            TextView textViewContManagerName = (TextView) baseViewHolder.getView(R.id.textviewcontmanagername);

            //真实的联系人姓名？
            TextView textViewContantPerson = (TextView) baseViewHolder.getView(R.id.textviewcontantperson);
            //真是的联系人电话信息
            TextView textViewContant = (TextView) baseViewHolder.getView(R.id.textviewcontant);
            //客户的预约时间
            TextView textViewBookingTime = (TextView) baseViewHolder.getView(R.id.textviewbookingtime);

            //已进站的 按钮内容？
//            RoundTextView textViewRepairIntoStation = (RoundTextView) baseViewHolder.getView(R.id.textviewrepairintostation);
//            //按钮的 改预约  按钮
//            RoundTextView textViewBookingChange = (RoundTextView) baseViewHolder.getView(R.id.textviewbookingchange);
//            //取消预约按钮
//            RoundTextView textViewBookingCancel = (RoundTextView) baseViewHolder.getView(R.id.textviewbookingcancel);
//            //确定预约按钮
//            RoundTextView textViewBookingSure = (RoundTextView) baseViewHolder.getView(R.id.textviewbookingsure);


            //车牌名称
            CommUtils.setText(textViewCarnumberName, carNumber);
            //标签名称
            CommUtils.setText(textViewRepairTypeTag, typeRepair);

            //获取车辆古文的名称
            CommUtils.setText(textViewContManagerName, managerName);

            //获取联系人姓名
            CommUtils.setText(textViewContantPerson, personName);
            //联系人电话
//            CommUtils.setText(textViewContant, personPhone);
            CommUtils.setText(textViewContant, StringCodeUtils.mobileEncrypt(personPhone));
            //预约时间
            CommUtils.setText(textViewBookingTime, timeResult);
            //该预约单子的状态-分配状态
            CommUtils.setText(textViewRepairAssignedState, itemState);

            //三个按钮的点击状态

        }

    }

}
